<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="../css/bootstrap.min.css">
    <script src="../../configure.js"></script>
</head>
<body style="background-color: #F5F6F7">
<div class="container" style="background-color:white;margin-top: 20px">
    <form id="form" style="margin:10px 0px 10px">
        <span style="font-size:larger;color: black">修改用户</span>
        <hr style="border: black 1px solid">
        <div class="form-group">
            <label for="userPhone">电话号</label>
            <input id="userPhone" type="text" class="form-control" name="userPhone"  placeholder="请输入电话号">
        </div>
        <button id="find"  type="button" class="btn btn-danger form-control ">查询</button>
        <div id="success">



        <div class="form-group">
            <label for="userName">用户姓名</label>
            <input type="text" class="form-control" name="userName" id="userName" placeholder="请输入用户姓名">
        </div>
<!--        <div class="form-group">-->
<!--            <label for="userPassword">用户密码</label>-->
<!--            <input type="password" class="form-control" name="userPassword" id="userPassword">-->
<!--        </div>-->
        <div class="form-group">
            <label>性别 :</label>
            <label class="radio-inline">
                <input type="radio" name="sex" value="man">男
            </label>
            <label class="radio-inline">
                <input type="radio" name="sex" value="woman">女
            </label>
        </div>
        <div class="form-group">
            <label for="age">年龄</label>
            <input type="text" class="form-control" name="age" id="age" placeholder="请输入年龄">
        </div>

        <div class="form-group">
            <label for="IdCard">身份证号</label>
            <input type="text" class="form-control" name="IdCard" id="IdCard" placeholder="请输入身份证号">
        </div>
        <div class="form-group">
            <label for="address">详细地址</label>
            <input type="text" class="form-control" name="address" id="address" placeholder="请输入详细地址">
        </div>

        <button type="submit" class="btn btn-danger form-control ">修改</button>
        </div>
    </form>
</div>
</body>
<script src="../js/jquery-3.3.1.min.js"></script>
<script src="../js/bootstrap.min.js"></script>
<script src="../js/distpicker.data.js"></script>
<script src="../js/distpicker.js"></script>
<script src="../layer/layer.js"></script>
<script>
    $(function(){
        $("#success").hide();
        $("#find").click(function(){
            var userPhone = $("#userPhone").val();
            let phoneReg = /(^1[3|4|5|7|8]\d{9}$)|(^09\d{8}$)/;
            if (userPhone=="") {
                layer.msg("手机号码不能为空");
                return false
            }else{
                if (!phoneReg.test(userPhone)) {
                    layer.msg("手机号格式不正确");
                    return false
                }
            }
            $.getJSON(url+"/admin/adminSelectUser",{userPhone:userPhone},function(data){
                console.log(data)
                layer.msg(data.message);
                if(data.message == "查询成功"){
                    $("#success").show();
                    $("#find").hide();
                    // $("#userPassword").val("");
                    $("#IdCard").val(data.data[0].idCard);
                    $("#userName").val(data.data[0].userName);
                    $("#address").val(data.data[0].address);
                    $("#age").val(data.data[0].age);
                }
                
            })
        });

        $("#form").submit(function(){
           
            let userPhone = $("#userPhone").val();
            let userName = $("#userName").val();
            let IdCard = $("#IdCard").val();
            let age = $("#age").val();

            if (userPhone=="") {
                layer.msg("手机号码不能为空");
                return false
            }else{
                if (!phoneReg.test(userPhone)) {
                    layer.msg("手机号格式不正确");
                    return false
                }
            }
            if (userName=="") {
                layer.msg("姓名不能为空");
                return false
            }
            if (IdCard=="") {
                layer.msg("身份证号不能为空");
                return false
            }
            if (age=="") {
                layer.msg("年龄不能为空");
                return false
            }

            $.post(url+"/admin/adminUpdateUser",{
                userPhone:userPhone,
                userName:userName,
                IdCard:IdCard,
                age:age
            },function(data){
                //layer.msg(data.data.message);
                console.log(data)
                if(data.code == 1){
                    //录入成功
                    layer.msg("修改成功");
                    $("input").val("");
                    // $("input:eq(1)").val("顺丰速运");
                }else{
                    layer.msg("修改失败");
                    //录入失败
                }
            });
            return false
        });
    });
</script>
</html>